package cn.xfdzx.android.apps.shop.presenter;

import android.util.Log;
import android.widget.Toast;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.BuyOftenGoodsBeen;
import cn.xfdzx.android.apps.shop.contract.PaySuccessfulContract;
import cn.xfdzx.android.apps.shop.model.PaySuccessfulLikeModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class PaySuccessfulLikePresenter extends BasePresenter<PaySuccessfulContract.View> implements PaySuccessfulContract.Presenter {

    private PaySuccessfulContract.Model model;

    public PaySuccessfulLikePresenter() {
        model = new PaySuccessfulLikeModel();
    }

    @Override
    public void initList(boolean isRefresh, boolean isLoading, String page, String limit) {
        if (!isViewAttached()) {
            return;
        }
        if (isLoading){
            mView.showLoading();
        }
        model.initList(page, limit)
                .compose(RxScheduler.<BuyOftenGoodsBeen>Flo_io_main())
                .as(mView.<BuyOftenGoodsBeen>bindAutoDispose())
                .subscribe(new Consumer<BuyOftenGoodsBeen>() {
                    @Override
                    public void accept(BuyOftenGoodsBeen bean) throws Exception {
                        if (isLoading){
                            mView.hideLoading();
                        }
                        if (isRefresh){
                            mView.finishRefresh();
                        }else {
                            mView.finishLoadMore();
                        }
                        mView.onListSuccess(bean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        if (isLoading){
                            mView.hideLoading();
                        }
                        if (isRefresh){
                            mView.finishRefresh();
                        }else {
                            mView.finishLoadMore();
                        }
                        mView.onError(throwable);
                    }
                });
    }
}
